package com.dearbinge.im.content.ofUser;

import com.dearbinge.data.api.ofUser.OfUserService;
import com.dearbinge.data.pojo.ofuser.Ofuser;
import com.dearbinge.utils.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "openfire用戶")
@RestController
@RequestMapping("/ofUserController")
@EnableAutoConfiguration
public class OfUserController {

    @Autowired
    private OfUserService ofUserService;

    /**
     * 新增/修改
     */
    @ApiOperation(value = "新增/修改",notes = "新增/修改")
    @RequestMapping(value = "addOrUpdate",method = RequestMethod.POST)
    public ResultMsg<String>  addOrUpdate(@RequestBody Ofuser ofuser){
        try {
            if (ofuser.getEncryptedpassword() != null){
                Integer dataCode = ofUserService.update(ofuser);
                if (dataCode > 0){
                    return ResultMsg.ok("修改成功");
                }
            }else {
                Integer dataCode = ofUserService.insert(ofuser);
                if (dataCode > 0){
                    return ResultMsg.ok("新增成功");
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return ResultMsg.error(500,"系统异常");
    }
}
